<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        class Vue{
            constructor(option){
                // option=>el data methods
                // 进行数据劫持 data 转发实例上面
                // console.log(option);
                this.initProxy(option.data);
                

            }
            initProxy(data){
                // 进行数据劫持 data
                // console.log(Object.keys(data));
                Object.keys(data).map(v=>{
                    // console.log(v);// num
                    // console.log(data[v]);// 107
                    Object.defineProperty(this,v,{
                    get:function(){
                        return data[v];//777
                    },
                    set:function(newVal){
                        data[v]=newVal;
                    }
                })
                })

            }
        };
        let vm=new Vue({
            data:{
                num:107
            }
        })
        console.log(vm.num);// 107


    </script>

</body>
</html>